//
//  YWDoEquipmentMissionCell.m
//  maintain
//
//  Created by kyo on 2017/4/26.
//  Copyright © 2017年 ewin. All rights reserved.
//

#import "YWDoEquipmentMissionCell.h"
#import "Masonry.h"
#import "UIColor+CustomColors.h"
#import "YWMacro.h"
#import "YWEquipment.h"
#import "YYLabel.h"
#import "YWCommonTool.h"
#import "YWEquipmentManager.h"

@interface YWDoEquipmentMissionCell()
@property (nonatomic, strong) YYLabel *titleLabel;

@property (nonatomic, strong) YYLabel *contentLabel;

@property (nonatomic, strong) YYLabel *detailLabel;
@end

@implementation YWDoEquipmentMissionCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUpSubviews];
    }
    return self;
}

- (void)setEquipmentArray:(NSArray *)equipmentArray{
    _equipmentArray = equipmentArray;
    YWEquipment * equipment = _equipmentArray.count?_equipmentArray[0]:nil;
    NSString *equipmentTypeName = [[YWEquipmentManager shareManager] equipmentTypeNameWithTypeId:equipment.equipmentTypeId];
    self.titleLabel.text = equipmentTypeName.length?equipmentTypeName:nil;
    NSInteger totalCount = _equipmentArray.count;
    self.contentLabel.text = [NSString stringWithFormat:@"共%ld个%@",(long)totalCount,NSLocalizedString(@"equipment", nil)];
}

- (void)setUpSubviews{
    UIView *superview = self.contentView;
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superview.mas_top).offset(8);
        make.left.mas_equalTo(superview.mas_left).offset(8);
        make.right.mas_equalTo(superview.mas_right).offset(-10);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_titleLabel.mas_bottom);
        make.left.mas_equalTo(_titleLabel.mas_left);
        make.right.mas_equalTo(self.detailLabel.mas_left);
        make.bottom.mas_equalTo(superview.mas_bottom).offset(-8);
    }];
    
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_contentLabel.mas_top);
        make.right.mas_equalTo(superview.mas_right).offset(-10);
        make.bottom.mas_equalTo(_contentLabel.mas_bottom);
        make.width.mas_equalTo(100);
    }];
}

- (void)clickLabelEvent:(id)sender{
    //点击事件
    if ([self.delegate respondsToSelector:@selector(clickLabelEvent:)]) {
        [self.delegate clickLabelEvent:self];
    }
}

- (YYLabel *)titleLabel{
    if (!_titleLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.font = kContentFont;
        label.textColor = [UIColor blackColor];
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickLabelEvent:)]];
        label.userInteractionEnabled = YES;
        _titleLabel = label;
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (YYLabel *)contentLabel{
    if (!_contentLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.font = KSmallContentFont;
        label.textColor = [UIColor customTextGrayBlackColor];
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickLabelEvent:)]];
        label.userInteractionEnabled = YES;
        _contentLabel = label;
        [self.contentView addSubview:_contentLabel];
    }
    return _contentLabel;
}

- (YYLabel *)detailLabel{
    if (!_detailLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.font = KSmallContentFont;
        label.textColor = [UIColor customTextGrayBlackColor];
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickLabelEvent:)]];
        label.userInteractionEnabled = YES;
        label.text = @"完善更多信息 >";
        _detailLabel = label;
        [self.contentView addSubview:_detailLabel];
    }
    return _detailLabel;
}

@end
